'use strict';

import Vue from 'vue'
import util from '@/util/Util'
import qs from 'qs'

const _vue = new Vue()

const _user = {
	// 获取登录token
	'getToken': function(param) {
		return _vue.$axios.get(util.getServerUrl('/user/token'))
			.then(function(response) {
				if(param.success) {
					param.success(response)
				}
				return response
			})
			.catch(function(error) {
				console.log(error)
			})
	},
	// 用户登录
	'signIn': function(param) {
		return _vue.$axios.post(util.getServerUrl('/user/signIn'), {
				'phone': param.phone,
				'password': param.password,
			})
			.then(function(response) {
				if(param.success) {
					param.success(response)
				}
				return response
			})
			.catch(function(error) {
				console.log(error)
			})
	},
	// 用户注册
	'signUp': function(param) {
		return _vue.$axios.post(util.getServerUrl('/user/signUp'), {
				'phone': param.phone,
				'userName': param.userName,
				'password': param.password,
				'confirmPassword': param.confirmPassword,
			})
			.then(function(response) {
				if(param.success) {
					param.success(response)
				}
				return response
			})
			.catch(function(error) {
				console.log(error)
			})
	},
	// 获取用户信息
	'userInfo': function(param) {
		return _vue.$axios.get(util.getServerUrl('/user/userInfo'))
			.then(function(response) {
				if(param.success) {
					param.success(response)
				}
				return response
			})
			.catch(function(error) {
				console.log(error)
			})
	},
}

export default _user